<template>
  <div class="bonus">
    <nav-bar title="积分福利购"></nav-bar>
    <div class="bonus-content"
         style="height:100%;">
      <van-pull-refresh v-model="refreshing"
                        @refresh="onRefresh">
        <van-list v-model="loading"
                  :finished="finished"
                  finished-text="没有更多了"
                  @load="onLoad">
          <good-card v-for="item in list"
                     :key="item.key">
            <template #last-right>
              <span class="bonus-snap"
                    @click="goGood">立即换购</span>
            </template>
          </good-card>
        </van-list>
      </van-pull-refresh>
    </div>
  </div>
</template>

<script>
import NavBar from '@/components/NavBar'
import GoodCard from '@/components/GoodCard'
import SecProgress from '@/components/SecProgress'
import getList from '@/api/home'
export default {
  data () {
    return {
      list: [],
      loading: false,
      finished: false,
      refreshing: false,
    };
  },
  components: {
    NavBar,
    GoodCard,
    SecProgress
  },
  created () {
  },
  methods: {
    onLoad () {
      if (this.refreshing) {
        this.list = [];
        this.refreshing = false;
      }
      getList().then(res => {
        this.list = [...this.list, ...res.data.rows]

        this.loading = false;
        if (this.list.length >= res.data.total) {
          this.finished = true;
        }
      })
    },
    onRefresh () {
      // 清空列表数据
      this.finished = false;
      // 重新加载数据
      // 将 loading 设置为 true，表示处于加载状态
      this.loading = true;
      this.onLoad();
    },
    goGood () {
      console.log(222);
    }
  }
}

</script>
<style lang='scss' scoped>
.bonus {
  @include wh100;
  @include flex-column;
  background-color: #eeeeee;
  .bonus-content {
    overflow-y: auto;
    flex: 1;
    width: 100%;
    box-sizing: border-box;
    padding: 0.1rem;
    .good-card {
      margin-bottom: 0.15rem;
    }
    .bonus-snap {
      height: 0.4rem;
      width: 1.2rem;
      @include flex-center;
      border-radius: 0.1rem;
      background-color: #d92a0d;
      font-size: 0.24rem;
      color: #fefefe;
    }
  }
}
</style>